(function() {
    function Router() {
        this.routes = {};
        this.currentURL = '';
    }
    Router.prototype.route = function(path, callback) {
        this.routes[path] = callback || function() {};
    }
    Router.prototype.refresh = function() {
        this.currentURL = location.hash.slice(1);
        if (this.routes[this.currentURL]) {
            this.routes[this.currentURL]();
        } else {
            this.routes['index']();
        };
    }
    Router.prototype.init = function() {
        window.addEventListener('load', this.refresh.bind(this), false);
        window.addEventListener('hashchange', this.refresh.bind(this), false);
    }
    Window.Router = new Router;
    Window.Router.init();
})();